package com.tenwives.ashop.kernel;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.util.List;

@AllArgsConstructor
@Data
@ToString
public class Shop {
    String name;
    List<Special> specials;
    List<Coupon> coupons;
    List<Fruit> fruits;

    public Trade createTrade(Customer customer, List<Goods> goodsList) {
        return new Trade(this, customer, coupons, specials, goodsList);
    }

    public Fruit findFruit(String name) {
        return fruits.stream().filter(f -> f.name.equals(name)).findFirst().orElseThrow(() -> new AException("水果不存在"));
    }

    public Goods sellFruits(String name, double weight) {
        return new Goods(findFruit(name), weight);
    }

    public void loadFruits(String name, double price) {
        this.fruits.add(new Fruit(name, price));
    }

    public void offerCoupon(Coupon coupon) {
        this.coupons.add(coupon);
    }

    public void offerSpecial(Special special) {
        this.specials.add(special);
    }
}
